package netTrackerGUI;
import java.awt.Dimension;

import netTracker.Track;
import javax.swing.*;

/**
 * 	The GUI for each track in NetTracker.
 * 	Draws rectangles to represent each cell.
 */

@SuppressWarnings("serial")			// GUI does not need to be serialized

public class TrackGUI extends JPanel{
	/** The track represented by this GUI. */
	Track track;
	/** The GUIs used to represent each cell. */
	CellGUI[] cells;
	/** The number of this track. */
	int trackNumber;
	
	/**
	 * Constructs a Track GUI.
	 * @param track the track to represent.
	 */
	public TrackGUI(Track track, NetTrackerGUI netTrackerGUI, int trackNumber){
		this.track = track;	
		this.trackNumber = trackNumber; 
		
		/** Create and instantiate each individual CellGUI, and add it to the panel: */
		cells = new CellGUI[track.getCells().length];
		for (int i=0; i<cells.length; i++){
			// Create each cell GUI with an x,y coordinate according to its position.
			cells[i] = new CellGUI(track.getCells()[i], netTrackerGUI, trackNumber, i);
			add(cells[i]);
		}
	}
	
	/** @return the cell GUIs in the track. */
	public CellGUI[] getCells(){
		return cells;
	}
	
	/** Retrieves a cell GUI at a particular index. 
	 *  Wraps around using modulus.
	 *  @return the cell GUI requested.
	 *  @param index the index of the cell GUI to get. */
	public CellGUI getCell(int index){
		if (index == -1)	// Account for wrap-around
			return cells[cells.length-1];
		return cells[index%cells.length];
	}
	
	/** Override size methods to ensure a correct track size: */
    public Dimension getMinimumSize()
    { return new Dimension(NetTrackerGUI.CELLWIDTH,NetTrackerGUI.HEIGHT); }
    public Dimension getMaximumSize()
    { return getMinimumSize(); }
    public Dimension getPreferredSize()
    { return getMinimumSize(); }
}